/**
 * Created by wxbing (wxbing000@163.com) on 2021/7/28.
 */
const fs = require("fs");
const readline = require('readline');
// fs.readFile('E:\\sbc\\doc\\SBC-1.2.0-LINUX7-20210309\\cin\\etc\\config.client', function (err, data) {
//     if (err) {
//         return console.error(err);
//     }
//     console.log("异步读取文件", data.toString());
// });


async function processLineByLine() {
    const fileStream = fs.createReadStream('E:\\sbc\\doc\\SBC-1.2.0-LINUX7-20210309\\cin\\etc\\config.client');

    const rl = readline.createInterface({
        input: fileStream,
        crlfDelay: Infinity
    });
    // 注意：我们使用 crlfDelay 选项将 input.txt 中的所有 CR LF 实例（'\r\n'）识别为单个换行符。

    rl.on('line', (line) => {
        console.log(`文件中的每一行: ${line}`);
    });
}

// processLineByLine();

// const configClientFileStream = fs.createReadStream('E:\\sbc\\doc\\SBC-1.2.0-LINUX7-20210309\\cin\\etc\\config.client');
// const configClientLine = readline.createInterface({
//     input: configClientFileStream,
//     crlfDelay: Infinity
// });
// const vnNumPatten = new RegExp('^127\.0\.0\.1.+text0ines.+VN.+$');
// configClientLine.on('line', (line) => {
//     // console.log(`文件中的每一行: ${line}`);
//     console.log(vnNumPatten.test(line));
// });


function promiseDemo() {
    return new Promise(() => {
        let vnNum = 0;
        const configClientFileStream = fs.createReadStream('E:\\sbc\\doc\\SBC-1.2.0-LINUX7-20210309\\cin\\etc\\config.client');
        const configClientLine = readline.createInterface({
            input: configClientFileStream,
            crlfDelay: Infinity
        });
        const vnNumPatten = new RegExp('^127\.0\.0\.1.+text0ines.+VN.+$');
        configClientLine.on('line', (line) => {
            console.log(`文件中的每一行: ${line}`);
            if (vnNumPatten.test(line)) {
                vnNum++;
            }
        });
        return vnNum;
    });
}

promiseDemo().then((data) => {
    console.log(data);
})

